package com.iflysse.dao;

import com.iflysse.pojo.po.common.CommonPoResp;
import com.iflysse.pojo.po.req.DealResourceFeedbackPoReq;
import com.iflysse.pojo.po.req.ResourceFeedbackConditionPoReq;
import com.iflysse.pojo.po.resp.ResourceFeedbackPoResp;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public interface ResourceFeedbackDao {
    /**
     * 获取符合条件的反馈总条数
     * @param resourceFeedbackConditionPoReq
     * @return
     */
    @Select("<script>"
            + "select count(*) from tb_resource_feedback where 1=1"
            + "<if test='courseId != null and courseId != &apos;&apos;'> "
            + "and resource_id = #{courseId} "
            + "</if>"
            + "<if test='feedbackType != null and feedbackType != &apos;&apos;'> "
            + "and resource_type = #{feedbackType}"
            + "</if>"
            + "<if test='state != null and state!= &apos;&apos;'> "
            + "and state = #{state}"
            + "</if>"
            + "</script>")
    Long getTotalAmountByCondition(ResourceFeedbackConditionPoReq resourceFeedbackConditionPoReq) throws SQLException;

    /**
     * 获取符合条件的反馈分页列表
     * @param resourceFeedbackConditionPoReq
     * @return
     */
    @Select("<script>"
            + "select * from tb_resource_feedback where 1=1"
            + "<if test='courseId != null and courseId != &apos;&apos;'> "
            + "and resource_id = #{courseId} "
            + "</if>"
            + "<if test='feedbackType != null and feedbackType!= &apos;&apos;'> "
            + "and resource_type = #{feedbackType}"
            + "</if>"
            + "<if test='state != null and state!= &apos;&apos;'> "
            + "and state = #{state}"
            + "</if>" +
            "<bind name='start' value='(pageBeanPoReq.pageIndex-1)*pageBeanPoReq.pageSize'></bind>"
            + "limit #{start},#{pageBeanPoReq.pageSize}" +
            "</script>")
    @Results({
            @Result(property = "resourceFeedbackId",column = "resource_feedback_id"),
            @Result(property = "resourceFeedbackTitle",column = "feedback_title"),
            @Result(property = "courseName",column = "course_name"),
            @Result(property = "chapterName",column = "chapter_name"),
            @Result(property = "feedbackStudentName",column = "student_name"),
            @Result(property = "feedbackTime",column = "feedback_time"),
    })
    List<ResourceFeedbackPoResp> getResourceFeedbackByConditionAndPage(ResourceFeedbackConditionPoReq resourceFeedbackConditionPoReq) throws SQLException;


    /**
     * 处理反馈
     * @param dealResourceFeedbackPoReq
     * @return
     */
    @Update("update tb_resource_feedback set state = #{state} where resource_feedback_id = #{resourceFeedbackId}")
    int dealResourceFeedback(DealResourceFeedbackPoReq dealResourceFeedbackPoReq) throws SQLException;
}
